<template>
	<view>
		<view class="container" v-if="info.created_at">
			<view class="s-cmt-cell">
				<view class="s-header-box">
					<view class="s-userinfo-box">
						<image :src="info.user_to.avatar_url" class="s-avatar"></image>
						<view class="s-nickname-box">
							<view class="s-cmt-nickname">{{info.user_to.nick_name}}</view>
							<view class="s-cmt-time">{{info.created_at}}</view>
						</view>
					</view>
				</view>
				<view class="s-cmt-content">
					{{info.content}}
				</view>
			</view>
			<view class="s-empty"></view>
			<view class="s-cmt-title">全部回复（{{total}}）</view>
			<view class="s-cmtbox">
				<view class="s-cmt-cell" v-for="(item,index) in consult_list" :key="index">
					<view class="s-header-box">
						<view class="s-userinfo-box">
							<image :src="item.user_to.avatar_url" class="s-avatar"></image>
							<view class="s-nickname-box">
								<view class="s-cmt-nickname">{{item.user_to.nick_name}}</view>
								<view class="s-cmt-time">{{item.created_at}}</view>
							</view>
						</view>
					</view>
					<view class="s-cmt-content">
						{{item.content}}
					</view>
				</view>
			</view>
			<s-no-data v-if="consult_list.length<=0&&moreData===false" :fixed="false" :imgUrl="$s.config.getConfig('NoDataImgUrlA')">
				{{$s.config.getConfig('NoDataTitle')}}
			</s-no-data>
			<s-loadmore v-if="moreData"></s-loadmore>
			<s-nomore v-if="consult_list.length>0&&moreData===false"></s-nomore>
			<s-scroll-top :scrollTop="scrollTop"></s-scroll-top>
			<view class="s-operation">
				<!--处理iphonex xr 等手机底部兼容-->
				<view class="s-operation-inner">
					<view class="s-btn-comment" @tap="consult_evaluate">发表你的评论...</view>
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',//咨询id
				pid:'',//上级评价ID，0表示顶级
				total:0,//评论条数
				scrollTop: 0,
				paging:null,
				moreData:true,
				consult_list:[],//咨询评论列表
				info:{} // 详情数据
			}
		},
		onLoad(options){
			this.id = options.id
			this.pid = options.pid
		},
		async onShow(){
			await this.getConsultEvaluateOneList()
		},
		methods: { 
			//二级评论列表
			async getConsultEvaluateOneList(callback) {
				const paging =  this.$s.model.consult.getConsultEvaluateOneList({id:this.id,pid:this.pid})
				this.paging = paging
				const res = await paging.getMoreData()
				if (!res) {
					return
				}
				this.consult_list = res.accumulator
				this.moreData = res.moreData
				this.total = res.total || 0
				this.info = res.info
			},
			//评论跳转
			async consult_evaluate(){
				return await this.$s.uniApi.navigateTo({url:'../consult_evaluate/consult_evaluate?pid='+this.pid+'&id='+this.id});
			} 
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		//下拉刷新
		async onPullDownRefresh() {
			await this.getConsultEvaluateOneList()
			uni.stopPullDownRefresh()
		},
		//上拉加载更多
		async onReachBottom() {
			const res = await this.paging.getMoreData()
			if(!res){
				return
			}
			this.consult_list = res.accumulator
			this.moreData = res.moreData
			this.total = res.total || 0
		}
	}
</script>

<style lang="scss" scoped>
@import 'consult_evaluate_one.scss';
</style>
